package com.yz.transfer;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
public class DealData {
    public static void main(String[] args) {
        ExcelReader reader = ExcelUtil.getReader("D:/地址标准化-国省道.xlsx");
        List<List<Object>> readAll = reader.read();
        List<List<String>> rows = new ArrayList<>();
        List<String> row1 = CollUtil.newArrayList("文件夹", "名称", "经度", "纬度");
        rows.add(row1);
        readAll.forEach(datas -> {
            List<String> strings = new ArrayList<>(8);
            strings.add(datas.get(0).toString());
            strings.add(datas.get(1).toString());
            Map<String, Double> wgs84 = CoordinateTransferUtils.gcj02ToWgs84(Double.parseDouble(datas.get(2).toString()),Double.parseDouble(datas.get(3).toString()));
            strings.add(wgs84.get("lon")+"");
            strings.add(wgs84.get("lat")+"");
            rows.add(strings);
        });
        //通过工具类创建writer
        ExcelWriter writer = ExcelUtil.getWriter("D:/地址标准化-国省道20240913.xlsx");
        //跳过当前行，既第一行，非必须，在此演示用
        writer.passCurrentRow();
        //合并单元格后的标题行，使用默认标题样式
        writer.merge(row1.size() - 1, "转换后的数据");
        //一次性写出内容，强制输出标题
        writer.write(rows, true);
        //关闭writer，释放内存
        writer.close();


    }
}
